package com.example.compose

import android.os.Bundle
import android.view.Surface
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.Composable
import androidx.compose.ambient
import androidx.compose.unaryPlus
import androidx.ui.core.*
import androidx.ui.foundation.DrawImage
import androidx.ui.foundation.shape.corner.RoundedCornerShape
import androidx.ui.layout.*
import androidx.ui.material.*
import androidx.ui.material.surface.Surface
import androidx.ui.res.imageResource
import androidx.ui.text.style.TextOverflow
import androidx.ui.tooling.preview.Preview

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                NewsStory("Android2")
            }
        }
    }
}

@Composable
fun NewsStory(name: String) {
    val image = +imageResource(R.drawable.header)

    Column(crossAxisSize = LayoutSize.Expand,
        modifier=Spacing(8.dp)
            ) {
        Container(expanded = true, height = 180.dp) {
            Clip(shape = RoundedCornerShape(8.dp)) {
                DrawImage(image)
            }
        }
        HeightSpacer(16.dp)

        Text("A day wandering through the sandhills in Shark " +
                "Fin Cove, and a few of the sights I saw",
            maxLines = 2, overflow = TextOverflow.Ellipsis,
            style = (+themeTextStyle { h6 }).withOpacity(0.87f))
        Text("Davenport, California",
            style = (+themeTextStyle { body2 }).withOpacity(0.87f))
        Text("December 2018",
            style = (+themeTextStyle { body2 }).withOpacity(0.6f))
        
    }


}



/*@Composable
fun TutorialPreviewTemplate(
    colors: MaterialColors = lightThemeColors,
    typography: MaterialTypography = themeTypography
) {
    val context = +ambient(ContextAmbient)
    val previewPosts = getPostsWithImagesLoaded(posts.subList(1, 2), context.resources)
    val post = previewPosts[0]
    MaterialTheme(colors = colors, typography = typography) {
        Surface {
            PostCardTop(post)
        }
    }
}*/

@Preview
@Composable
fun DefaultPreview() {
    MaterialTheme {
        NewsStory("Android1")
    }
}
